package LC;

import java.util.*;

/**
 * @ClassName LC145
 * @Description: TODO
 * @Author hl
 * @Date 2020/5/31
 * @Version V1.0
 **/
public class LC145 {
    public List<Integer> postorderTraversal(TreeNode root) {
       List<Integer> list=new ArrayList<>();
       if(root==null){
           return  list;
       }
        Stack<TreeNode> stack=new Stack<>();
        stack.push(root);
        while (!stack.isEmpty()){

            TreeNode temp=stack.pop();
            list.add(temp.val);
            if(temp.left!=null){
                stack.push(temp.left);
            }
            if(temp.right!=null){
                stack.push(temp.right);
            }
        }
         Collections.reverse(list);
        return list;
    }
}
